package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class FilmAddPage extends InternalPage {

	public FilmAddPage(PageManager pages) {
		super(pages);
	}

	@FindBy(name = "imdbid")
	private WebElement imdbField;

	@FindBy(name = "name")
	private WebElement nameField;

	@FindBy(name = "year")
	private WebElement yearField;

	@FindBy(name = "notes")
	private WebElement notesField;

	@FindBy(name = "submit")
	private WebElement submitButton;

	public FilmAddPage setNameField(String text) {
		nameField.sendKeys(text);
		return this;
	}

	public FilmAddPage setImdbField(String text) {
		imdbField.sendKeys(text);
		return this;
	}

	public FilmAddPage setYearField(String text) {
		yearField.sendKeys(text);
		return this;
	}

	public FilmAddPage setNotesField(String text) {
		notesField.sendKeys(text);
		return this;
	}

	public FilmAddPage clickSubmitButon() {
		submitButton.click();
		return this;
	}

	public FilmAddPage ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.id("imdbsearch")));
		return this;
	}

}
